﻿using GC_FFW.BusinessEntities.Abstractions.Interfaces.Forecast;

namespace GC_FFW.BusinessEntities.Forecast
{
	public class ForecastData : IForecastData
	{
		#region IForecastData Members

		public ITeam HomeTeam { get; set; }

		public ITeam AwayTeam { get; set; }

		public IPersonalConfrontationStatistics PersonalConfrontationStatistics { get; set; }

		public ICoefficients Coefficients { get; set; }

		#endregion

		#region ICloneable Members

		public object Clone()
		{
			return new ForecastData
			{
				AwayTeam = AwayTeam != null ? AwayTeam.Clone() as ITeam : null,
				HomeTeam = HomeTeam != null ? HomeTeam.Clone() as ITeam : null,
				Coefficients = Coefficients != null ? Coefficients.Clone() as ICoefficients : null,
				PersonalConfrontationStatistics = PersonalConfrontationStatistics != null
					? PersonalConfrontationStatistics.Clone() as IPersonalConfrontationStatistics
					: null,
			};
		}

		#endregion

		#region IUpdateTeamOperations Members

		public void UpdateName(string newName, bool? isHomeTeam = null)
		{
			if (!isHomeTeam.HasValue) return;

			if (isHomeTeam.Value && HomeTeam != null)
				HomeTeam.UpdateName(newName);
			else if (AwayTeam != null)
				AwayTeam.UpdateName(newName);

			if (PersonalConfrontationStatistics != null)
				PersonalConfrontationStatistics.UpdateName(newName, isHomeTeam);
		}

		#endregion
	}
}
